package project2.ui.manage;

import project2.config.Config;
import project2.resources.Images;
import project2.ui.MainFrame;
import project2.ui.manage.operate.MenuChoose;

import javax.swing.*;
import java.awt.*;

/**
 * 菜单面板
 */
public class PopupMenuPanel extends JPanel {
    private static final long serialVersionUID = 1L;

    // 组件
    public GameButton startGameButton;// 开始按钮
    public GameButton exitGameButton;// 退出按钮
    public GameButton top10ScoresButton;// 分数记录按钮
    public GameButton helpButton;// 帮助按钮
    // 人工操作
    public final MenuChoose menuChoose;// 选择菜单

    public PopupMenuPanel(MainFrame mainFrame) {
        menuChoose = new MenuChoose(mainFrame);// 选择菜单

        JLabel logoLabel = new JLabel();
        logoLabel.setIcon(new ImageIcon(Images.MY_PLANE_IMG));

        this.startGameButton = new GameButton("重新游戏");
        this.startGameButton.addActionListener(menuChoose);
        this.startGameButton.setOpaque(false);// 设置为透明

        this.top10ScoresButton = new GameButton("分数记录");
        this.top10ScoresButton.addActionListener(menuChoose);
        this.top10ScoresButton.setOpaque(false);

        this.helpButton = new GameButton("帮    助");
        this.helpButton.addActionListener(menuChoose);
        this.helpButton.setOpaque(false);

        this.exitGameButton = new GameButton("离开游戏");
        this.exitGameButton.addActionListener(menuChoose);
        this.exitGameButton.setOpaque(false);

        JPanel logoPanel = new JPanel();
        logoPanel.setOpaque(false);
        logoPanel.add(logoLabel);// 默认流式居中布局

        JPanel buttonPanel = new JPanel();
        buttonPanel.setOpaque(false);
        buttonPanel.setLayout(new GridLayout(4, 1, 0, 10));// 网格布局
        buttonPanel.add(startGameButton);
        buttonPanel.add(top10ScoresButton);
        buttonPanel.add(helpButton);
        buttonPanel.add(exitGameButton);
        Dimension d = new Dimension(Config.POP_UP_MENU_PANEL_WIDTH, Config.POP_UP_MENU_PANEL_HEIGHT);
        buttonPanel.setSize(d);
        buttonPanel.setPreferredSize(d);

        JPanel mainPanel = new JPanel();
        mainPanel.setOpaque(false);
        mainPanel.setLayout(new BorderLayout(0, 25));// 边界布局
        mainPanel.add(logoPanel, BorderLayout.NORTH);
        mainPanel.add(buttonPanel, BorderLayout.CENTER);

        this.setOpaque(false);
        this.add(mainPanel);// 默认流式居中布局
    }

}
